<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/css/dialog.css"/>
    <script src="/js/plugins/dialog2/js/dialog.min.js"></script>


    <script>
        $(function () {

            //获取当前登录用户的游记
            var user = JSON.parse(sessionStorage.getItem("user"));
            function query() {
                $.get("/users/" + user.id + "/travels", {currentPage:currentPage,pageSize: 3}, function (data) {
                    dataList = $.merge(dataList, data.list);
                    //数据渲染
                    $("#travels").renderValues({list: dataList}, {
                        setHref: function (item, value) {
                            var href = $(item).attr("href") + value;
                            $(item).attr("href", href);
                        }
                    });
                    currentPage += 1;
                    totalPage = data.pages;
                });
            }
            //定义一个临时当前页变量
            var currentPage = 1;
            var dataList = [];  //防止jrender丢失上一页数据设置
            var totalPage =1;


            //查询第一个游记,传入参数pageSize为分页的条数
           /* $.get("/users/" + user.id + "/travels", {currentPage:currentPage,pageSize: 5}, function (data) {
               // console.log(data);
                dataList = $.merge(dataList, data.list);
                //数据渲染
                $(".travels").renderValues({list: dataList}, {
                    setHref: function (item, value) {
                         var href = $(item).attr("href") + value;
                         $(item).attr("href", href);
                    }
                });
                currentPage += 1;
                totalPage = data.pages;
            });*/
            query();

            //屏幕滚动时间
            $(window).scroll(function () {
                if ($(window).height() + $(window).scrollTop() +1 >= $(document).height()) {
                    if (currentPage <= totalPage) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '人家可是有底线的哦!',
                            autoClose: 2500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });
        });

    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>


<div class="container" id="travels">
    <dl class="list" render-loop="list" >

        <dd>
            <a href="editTravels.html?id=" render-fun="setHref" render-key="list.id">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"></h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
                    <span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>

</body>
</html>
